const app = getApp()


Page({
  data: {
    base_url: 'https://vip.join.ink/',
    activity_list: [],
    // goods_list_hot: [],
    // goods_list_new: [],
    goods_list:[],
    active: 1,
    cardCur: 0,
    is_show: 2
  },

  comfirm() {
    this.setData({
      is_show: 2
    })
    wx.setStorageSync('is_show', 2)
  },


  
  fetch() {
    this.get_activity()
    this.get_goods_list()

    let is_show = wx.getStorageSync('is_show')
    if(is_show){
      this.setData({
        is_show
      })
    }else{
     wx.setStorageSync('is_show', 1)
      this.setData({
        is_show:1
      })
    }

  },
  // 活动收藏列表
  get_activity() {
    app.request('/user/favorites', {
      data: {
        type: 2
      }
    }).then(res => {
      if (res.data.code == 200) {
         console.log(res,"======================");
        this.setData({
          activity_list: res.data.data
        })
        // console.log(this.data.activity_list);
      }
    }).catch(err => {
      console.log(err);
    })
  },
  go_goods_info(e){
   var  id  =  e.currentTarget.dataset.id;
   if(id){
     wx.navigateTo({
       url: '/pages/goods_info/goods_info?id='+id,
     })
   }
  },

  // 商品收藏列表
  get_goods_list() {
    app.request('/user/favorites', {
      data: {
        type: 1
      }
    }).then(res => {
      if (res.data.code == 200) {
        // console.log(res);
        this.setData({
          // goods_list_new: res.data.sale_info
          goods_list: res.data.data
        })
        // console.log(this.data.goods_list_new);
      }
    }).catch(err => {
      console.log(err);
    })

    app.request('/getsaleList', {
      data: {
        is_hot: 1
      }
    }).then(res => {
      if (res.data.code == 200) {
        console.log(res);
        this.setData({
          goods_list_hot: res.data.data
        })
        console.log(this.data.goods_list_hot);
      }
    })
  },

  search(e) {
  },

  tab_click(e) {
    let flg = e.currentTarget.dataset.index
    this.setData({
      active: flg
    })
  },

  cardSwiper(e) {
    this.setData({
      cardCur: e.detail.current
    })
  },
  // ********************
  onLoad: function (options) {
    console.log(options, 'options');
    let scene = decodeURIComponent(options.scene);
    if (scene && scene != 'undefined') {
      wx.showToast({
        title: scene,
      })
      app.request("/user/doPageBinding", {
        method: "post",
        data: {
          code: scene
        }
      }).then(res => {
        console.log(res);
      })
    }
  },

  onShow: function () {
    this.fetch()
  }
})